#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* middleNode(struct ListNode* head) {
    if (head->next == NULL || head == NULL)
        return head;
    else
    {
        struct ListNode* slow = head;
        struct ListNode* fast = head;
        while (fast && fast->next)
        {
            //if(fast->next == NULL || fast->next->next == NULL)
                //return slow;
            slow = slow->next;
            fast = fast->next->next;
        }
        return slow;
    }
}